﻿
@using IOA.MES.DataAccess.Enum
@{
    ViewBag.Title = "库位编辑";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
    var warehouses = (List<IOA.MES.DataAccess.VModel.VWarehouse>)ViewBag.Warehouses;
}
@model IOA.MES.DataAccess.VModel.VWarehouseArea

@section Contents{
    <style>
        html {
            background-color: #FFF;
        }

        .layui-form-item .layui-input-inline {
            width: 300px;
        }

        .red {
            color: red;
        }
    </style>
}

<div class="layui-form" lay-filter="layuiadmin-app-form-list" style="padding: 20px 30px;">
    <div class="layui-form-item">
        <label class="layui-form-label">所属仓库：</label>
        <div class="layui-input-inline">
            <select id="selWarehouses" lay-filter="selWarehouses" name="WarehouseCode">
                @foreach (var item in warehouses)
                {
                    <option value="@item.WarehouseCode" @(Model != null && Model.WarehouseCode == item.WarehouseCode ? " selected" : "")>@($"{item.WarehouseName}-{item.WarehouseCode}")</option>
                }
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="red">*</span>库区代码：</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" lay-verify="required" name="AreaCode" value="@(Model==null?"":Model.AreaCode)" @(Model != null ? "disabled" : "")>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><span class="red">*</span>库区名称：</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" lay-verify="required" name="AreaName" value="@(Model==null?"":Model.AreaName)" @(Model != null ? "disabled" : "")>
        </div>
    </div>
    <div class="layui-form-item" style="text-align:center;padding-top: 20px;@(Model==null?"":"display:none;")">
        <input type="hidden" value="@(Model==null?0:Model.PkId)" name="PkId" />
        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="submit"><i class="layui-icon">&#xe605;</i>保存</button>
        <button class="layui-btn layui-btn-primary" onclick="parent.layer.close(parent.layer.getFrameIndex(window.name));"><i class="layui-icon">&#xe616;</i>取消</button>
    </div>
</div>

@section Scripts{
    <script>
        initLayui();
        function initLayui() {
            layui.use(['form', 'layer', 'index', 'laydate'], function () {
                var layer = layui.layer,
                    form = layui.form;

                form.on('submit(submit)', function (data) {
                    console.log(data.field);
                    var loadId = layer.load();
                    $.ajax({
                        url: "/Warehouse/EditWarehouseArea",
                        data: {
                            model: data.field
                        },
                        complete: function () {
                            layer.close(loadId);
                        },
                        success: function (res) {
                            if (res.ErrCode != 200) {
                                layer.msg(res.ErrMsg, { icon: 5 });
                                return;
                            }
                            layer.msg("保存成功！", { icon: 6, time: 1500 }, function () {
                                parent.layer.close(parent.layer.getFrameIndex(window.name));
                            });
                        }
                    });
                    return false;
                });
            });
        }
    </script>
}
